package owen.com.dxc;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class Start extends AppCompatActivity {

    private TextView tx, tx2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.start);
        tx = (TextView)findViewById(R.id.textView_sec);
        tx2 = (TextView)findViewById(R.id.textView);
        handler.sendEmptyMessageDelayed(0, 2000);
    }

    private int time = 5;
    private int time2 = 10;

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            tx.setText(time+"");
            if(time == 0){
                if(time2 == 0){
                    startActivity(new Intent(Start.this, Login.class));
                    finish();
                }else{
                    handler.sendEmptyMessageDelayed(0, 1000);
                    if(time2 == 5){
                        tx2.setText("老弟啊！耐心点！");
                    }
                    time2 --;
                }
            }else{
                if(time == 5){
                    handler.sendEmptyMessageDelayed(0, 0);
                }else {
                    handler.sendEmptyMessageDelayed(0, 2000);
                }
                time --;
            }
        }
    };

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}
